﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections.Generic;
using MySql.Data.MySqlClient;


public class ClienteDAO
{
    MySqlConnection connection = Database.getInstance.getConnection();

    public ClienteDAO()
    {

    }

    public List<ClienteDTO> getAll()
    {
        try
        {
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader reader;

            command.CommandText = "SELECT * FROM cliente";
            connection.Open();

            List<ClienteDTO> Cliente_List = new List<ClienteDTO>();

            reader = command.ExecuteReader();
            while (reader.Read())
            {
                ClienteDTO cliente = new ClienteDTO();
                cliente.Id = Convert.ToInt32(reader["idcliente"]);
                cliente.Idade = Convert.ToInt32(reader["idade"]);
                cliente.Endereco = (string)reader["Endereco"];
                cliente.Telefone = (string)reader["Telefone"];
                cliente.Complemento = (string)reader["Complemento"];
                cliente.Numero = Convert.ToInt32(reader["Numero"]);
                cliente.Cep = (string)reader["Cep"];
                cliente.Rg = (string)reader["rg"];
                cliente.Cpf = (string)reader["cpf"];
                Cliente_List.Add(cliente);
            }
            connection.Close();
            return Cliente_List;
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
}
